import oracledb

# 数据库连接信息
user = "bupps5@oboracle"
password = "aaAA11__"
host = "10.20.192.195"
port = 2881
service_name = "bupps5"

dsn = oracledb.makedsn(host=host, port=port, service_name=service_name)
print(dsn)

try:
    print(1)
    # 建立数据库连接
    connection = oracledb.connect(user=user, password=password, dsn=dsn, tcp_connect_timeout=5)
    print("成功连接到 OceanBase 的 Oracle 模式数据库")

    # 创建游标对象
    cursor = connection.cursor()

    # 执行 SQL 查询
    cursor.execute("SELECT * FROM aaa")

    # 获取查询结果
    results = cursor.fetchall()

    # 打印查询结果
    for row in results:
        print(row)

    # 关闭游标和连接
    cursor.close()
    connection.close()

except oracledb.Error as error:
    print(f"连接数据库时出错: {error}")
